#include "web_responder.h"

int main()
{
	SESSION_LIST current_session;
	char *char_op;
	USER_DATA *user_info;
		
	FILE *html_file;
	char get_char;
	char html_cache[PAGE_SIZE_];
	UINT_ i;
	
	char post_data[128];
	
	DB_LINKER db_linker;
	
	
	/*init*/
	/*session init*/
	/*session_Create(&current_session,sizeof(struct user_info));*/
	
	/*read main page from file*/
	
	html_file=fopen("index","r");
	i=0;
	for(get_char=getc(html_file);get_char!=EOF;get_char=getc(html_file))
	{
		html_cache[i]=get_char;
		i++;
	};
	fclose(html_file);
	html_cache[i]='\0';
	
	/*start link the database*/
	if(db_Connect(&db_linker,DB_USER,DB_PAS,DB_HOST)==NULL)/*ok go to the error page*/;
	
	
	while(FCGI_Accept()>=0)
	{
		/*get login info*/
				
		char_op=getenv("HTTP_COOKIE");
		
		if(char_op==NULL)
		{
			
			if(get_Post(post_data)==NULL)
			{
				show_Login(html_cache);
			}
			else
			{
				/*ok check login here*/
				
				printf("Content-Type:text/plain;charset=utf-8\n\n");
				printf("checking your user:%s",post_data);
				
			};
		}
		else
		{
			user_info=login_Check(char_op,&current_session);
			if(user_info==NULL)
			{
				if(get_Post(post_data)==NULL)
				{
					show_Login(html_cache);
				}
				else
				{
					/*ok check login here*/
					printf("Content-Type:text/plain;charset=utf-8\n\n");
					printf("checking your user:%s",post_data);
				};
				
			}
			else
			{
				/*well done start op*/
				
			};
			
		};
		
		
		session_Drop(&current_session);
		
	};
	return 0;
};
